<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>dexterind-flex-test2.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     DFLEX,               sensorAnalogInactive)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: dexterind-flex-test2.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * dexterind-flex.h provides an API for the Dexter Industries dFlex Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API to calibrate the sensor.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 23 June 2010</span>
<span class="comment"> * version 0.1</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="dexterind-flex_8h.html" title="ROBOTC Dexter Industries dFlex Sensor driver.">drivers/dexterind-flex.h</a>&quot;</span>

task main () {
  <span class="keywordtype">int</span> raw = 0;
  <span class="keywordtype">int</span> nrm = 0;
  <span class="comment">// Get control over the buttons</span>
  nNxtButtonTask  = -2;

  eraseDisplay();
  nxtDisplayTextLine(0, <span class="stringliteral">&quot;Dexter Industries&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;dFlex&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 2&quot;</span>);
  nxtDisplayCenteredTextLine(5, <span class="stringliteral">&quot;Connect sensor&quot;</span>);
  nxtDisplayCenteredTextLine(6, <span class="stringliteral">&quot;to S1&quot;</span>);
  wait1Msec(2000);

  eraseDisplay();
  nxtDisplayTextLine(0, <span class="stringliteral">&quot;dFlex Calibration&quot;</span>);
  nxtDisplayTextLine(2, <span class="stringliteral">&quot;Left:  set min&quot;</span>);
  nxtDisplayTextLine(3, <span class="stringliteral">&quot;Right: set max&quot;</span>);
  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Grey:  exit&quot;</span>);

  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="keywordflow">switch</span>(nNxtButtonPressed) {
      <span class="comment">// if the left button is pressed calibrate the black value for the sensor</span>
      <span class="keywordflow">case</span> kLeftButton:
                        <a name="a0"></a><a class="code" href="group__d_flex.html#gafec1f1b1b5145a264a6e5282b547631e">DFLEXcalLow</a>(DFLEX);
                        PlaySound(soundBeepBeep);
                        <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
                        <span class="keywordflow">break</span>;

      <span class="comment">// if the left button is pressed calibrate the white value for the sensor</span>
      <span class="keywordflow">case</span> kRightButton:
                        <a name="a1"></a><a class="code" href="group__d_flex.html#ga42974ea404ff3b6540996a40c4c70741">DFLEXcalHigh</a>(DFLEX);
                        PlaySound(soundBeepBeep);
                        <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
                        <span class="keywordflow">break</span>;
    }

    nxtDisplayClearTextLine(5);
    nxtDisplayClearTextLine(6);

    <span class="comment">// Read the raw value of the sensor</span>
    raw = <a name="a2"></a><a class="code" href="group__d_flex.html#ga6cb0d8975cddb152c9f484f7d2384a53">DFLEXvalRaw</a>(DFLEX);

    <span class="comment">// Read the normalised value of the sensor</span>
    nrm = <a name="a3"></a><a class="code" href="group__d_flex.html#ga50b86a054fdc97b337658fae58f1bd8e">DFLEXvalNorm</a>(DFLEX);

    <span class="comment">// Display the raw and normalised values</span>
    nxtDisplayTextLine(5, <span class="stringliteral">&quot;R: %4d N: %4d&quot;</span>, raw, nrm);

    <span class="comment">// Display the values for black and white</span>
    nxtDisplayTextLine(6, <span class="stringliteral">&quot;B: %4d W: %4d&quot;</span>, <a name="a4"></a><a class="code" href="group__d_flex.html#ga7d8e810df952320157207399755663aa">dflexlow</a>, <a name="a5"></a><a class="code" href="group__d_flex.html#gafcb9b240cb7b01f32bd00af317948a7c">dflexhigh</a>);
    wait1Msec(50);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: dexterind-flex-test2.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:41 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
